package cn.wolfcode.luowowo.article.controller;

import cn.wolfcode.luowowo.article.domain.Question;
import cn.wolfcode.luowowo.article.service.IQuestionService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.query.QuestionQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2019/7/20.
 */
@Controller
@RequestMapping("question")
public class QuestionController {
    @Reference
    private IQuestionService questionService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") QuestionQueryObject qo){
        PageInfo pageInfo =  questionService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "question/list";
    }
    @RequestMapping("changeState")
    @ResponseBody
    public Object changeState(Question question){
        //发布
        questionService.changeState(question);
       return new AjaxResult();
    }
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){
        //删除
        questionService.delete(id);
        return new AjaxResult();
    }
}
